home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb11.zip / SHEET.PAS < prev    next >
Pascal/Delphi Source File  |  1985-11-28  |  24KB  |  1,109 lines

  1. program sheet;    { for MS include (input,output) }
  2.  
  3. { for MS replace # with chr(...) around the number  below }
  4. {         WILD BLUE SKY PLANNING AREA                        }
  5. {                                                               }
  6. {   --Use a sparse matrix for the sheet var..NEW as           }
  7. {     needed                                                    }
  8. {                                                               }
  9. {                                                               }
  10. {                                                               }
  11. {                                                               }
  12. {                                                               }
  13. {                                                               }
  14. {                                                               }
  15.  
  16.  
  17. const
  18.   max_wide = 25;
  19.   max_long = 50;
  20.   maxfields = 40;     { for now }
  21.   ul_c      = #218;
  22.   ll_c         = #192;
  23.   ur_c         = #191;
  24.   lr_c         = #217;
  25.   v_c          = #179;
  26.   h_c          = #196;
  27.   maxitems     = 10;    { for menugen }
  28.   maxwindows   = 50;
  29.   maxevents    = 50;
  30.   current_attribute = #7;
  31.   bchk         = #220;
  32.   scale_factor = 65;
  33.  
  34. type
  35.   lst  = string[80];
  36.  
  37.   lst_p  = ^lst;
  38.  
  39.   dte = record
  40.     year : integer;
  41.     month : integer;
  42.     day : integer;
  43.    end;  { dte }
  44.  
  45.  
  46.  
  47.    duo = array[0..1] of integer;
  48.    quad = array[0..3] of integer;
  49.    position = duo;
  50.    line_type = quad;
  51.  
  52.  
  53.    range_type=record
  54.       top : duo;
  55.       bottom : duo;
  56.     end;  { rnage_type }
  57.  
  58.  
  59.   time_type = record
  60.     hour : byte;
  61.     minute : byte;
  62.     second : byte;
  63.    end;   { time_type }
  64.  
  65.   field = array[0..1] of lst;  { 1 for label, one for data }
  66.  
  67.  
  68.   window_p    = ^window_type;
  69.   
  70.   event_p =   ^event_record;
  71.  
  72. {
  73.   textstring_type = record
  74.      the_text : array[0..1000] of char;
  75.      strpos   : integer;
  76.      len      : integer;
  77.     end;
  78. }
  79.  
  80.  numstr = string[8];
  81.  
  82.  sheet_type = array[0..max_wide,0..max_long] of numstr;
  83.  
  84.  sheet_record_type = record
  85.      active_cell : duo;
  86.      cell_pos    : integer;
  87.      offset      : duo;
  88.     end;
  89.  
  90.  
  91.  window_type = record
  92.      ulLR     : QUAD;
  93.      job      : integer;
  94.     end;      { window_type }
  95.  
  96.  
  97.   setofchar   = set of char;
  98.  
  99.   regpack = record
  100.      ax,bx,cx,dx,bp,di,si,ds,es,flags  : integer;
  101.   end;
  102.  
  103.  
  104.  
  105.   event_record = record
  106.        active_window : window_p;
  107.        keypress      : boolean;
  108.        key           : char;
  109.        cursor_where  : position;
  110.        sysreq        : byte;
  111.      end;   { event_record }
  112.  
  113.  
  114.   system_status_type = record
  115.        active_window : byte;
  116.        drives_on     : byte;  { bit coded..1 on is A:, 2 on is B:, etc }
  117.        time          : time_type;
  118.        date          : dte;
  119.        cursor_where  : position;
  120.        window_move : boolean;
  121.      end;     { system_status_type }
  122.  
  123.  
  124.  
  125.   screen_position_pair_type = (char_byte, attr_byte);
  126.  
  127.   imagetype = array[1..25,1..80,char_byte..attr_byte] of char;
  128.  
  129.  
  130.   image_p     = ^imagetype;
  131.  
  132.   point_type  =  (r, d, o);
  133.  
  134.  
  135.  
  136. var
  137.   point_mode           : point_type;
  138.   range                : range_type;
  139.   rp_mode              : boolean;
  140.   ch , up, down, left, right, retrn, escape, home,
  141.   endd, pgup, pgdn,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,
  142.   f11,f12,f13,f14,f15  :  char;
  143.   i                    : integer;
  144.   wp                   : array[0..maxwindows] of window_p;   { window pointer }
  145.   wp_index             : integer;
  146.   control_set          : setofchar;
  147.   event                : event_record;
  148.   system_status        : system_status_type;
  149.   counter, max         : integer;
  150.   system_okset         : setofchar;
  151.   crtmode,page,width   : byte;
  152.   monobuffer           : imagetype absolute $B000:$0000;
  153.   colorbuffer          : imagetype absolute $B800:$0000;
  154.   buffer               : imagetype;
  155.   screen_stack         : array[0..maxwindows] of image_p;
  156.   sheet                : sheet_type;
  157.   sheet_record         : sheet_record_type;
  158.   sheet_corn, graph_corn : quad;
  159.   rl_ar    :  array[0..12] of real;
  160.   ar_sz    :  integer;
  161.   scale    : real;
  162.  
  163. {$Isheetlib.inc}
  164.  
  165.  
  166. function str2real(str:numstr):real;
  167.  
  168. var
  169.   i,j : integer;
  170.   tempr : real;
  171.  
  172.  
  173. function pwr10(exp:integer):real;
  174.  
  175. var
  176.   i : integer;
  177.   tempr : real;
  178.  
  179. begin
  180.   tempr := 1;
  181.   for i := 1 to exp do tempr := tempr*10;
  182.   pwr10 := tempr;
  183. end;
  184.  
  185.  
  186. begin { str2real}
  187.   tempr := 0;
  188.   j := 1;
  189.   for i := length(str) downto 1 do
  190.     begin
  191.       if str[i] in ['1'..'9'] 
  192.          then 
  193.            begin
  194.              tempr := tempr + ( (integer(str[i])-48) )*pwr10(j);
  195.              j := j + 1;
  196.            end;
  197.     end;
  198.   str2real := tempr;
  199. end; { str2real }
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208. procedure val_shell(st : numstr;var v :real; var cd :integer);
  209.  
  210. var
  211.   i : integer;
  212.   locstr : numstr;
  213.   ch     : char;
  214.  
  215. begin
  216.   locstr := '';
  217.   for i := 1 to length(st) do if (st[i] in ['0'..'9'])
  218.                 then locstr := locstr+st[i];
  219.  
  220. {----------}
  221.   gotoxy(1,15);
  222.   write('locstr ',locstr);
  223. {-----}
  224.  
  225.  
  226.  
  227.   val(locstr,v,cd);
  228. end;
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. procedure getxy(sh_co:duo;var xy:duo);   { returns phyciscal coords of sheet}
  236.                                  { location}
  237.  
  238. begin
  239.   xy[0] := 8*(sh_co[0]-1)+sheet_corn[0]+1;
  240.   xy[1] := sh_co[1]+sheet_corn[1]+1;
  241. end;
  242.  
  243.  
  244. procedure getshco(xy:duo;var shco:duo);   { returns sheet coords of phys xy }
  245.                                 { location }
  246.  
  247. begin
  248.   shco[0] := round((xy[0]-sheet_corn[0]-1)/8);
  249.   shco[1] := xy[1]-sheet_corn[1]-1;
  250. end;
  251.  
  252.  
  253.  
  254.  
  255. procedure gettime(var time : time_type);
  256.  
  257. var
  258.   local_time : time_type;
  259.   recpack    : regpack;  
  260.  
  261. begin
  262.   with recpack do
  263.    begin
  264.      ax := $2c shl 8;   { time of day request }
  265.    end;
  266.    msdos(recpack);      { dos call }
  267.  with recpack do
  268.   begin
  269.    local_time.second := dx shr 8;
  270.    local_time.minute := cx mod 256;
  271.    local_time.hour   := cx shr 8;
  272.    with local_time do
  273.     if hour > 12 then hour := hour - 12;
  274.  
  275.   end;
  276.  
  277.    time := local_time;
  278. end;  { gettime }
  279.  
  280.  
  281.  
  282.  
  283. procedure getdate(var local_date :dte);
  284.  
  285. var
  286.   recpack    : regpack;
  287.  
  288. begin
  289.   with recpack do
  290.    begin
  291.      ax := $2a shl 8;   { date request }
  292.    end;
  293.    msdos(recpack);      { dos call }
  294.   with recpack do
  295.   begin
  296.    local_date.year  := cx;
  297.    local_date.day   := dx mod 256;
  298.    local_date.month := dx shr 8;
  299.   end;
  300. end;  { getdate }
  301.  
  302.  
  303.  
  304. procedure draw_window(window_pointer : window_p);
  305.  
  306. var
  307.   x, y : integer;
  308.  
  309. begin
  310.   with Window_pointer^ do
  311. begin
  312.       for y := ullr[1] to ullr[3] do
  313.         for x := ullr[0] to ullr[2] do
  314.             putchar(x,y,' ');
  315.  
  316.      drawbox(ullr[0],ullr[1], (ullr[2] - ullr[0]), (ullr[3] - ullr[1]) );
  317.  
  318.  end;
  319.  end;
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330. procedure get_event(var event : event_record);
  331.  
  332.  
  333. begin
  334.  
  335. {event.keypress  := KeyPressed;}
  336.  
  337. { intrinisc boolean }
  338.  
  339. event.key := getchar(system_okset,false);
  340.  
  341. {-------------}
  342.  
  343. { write('event.key, ord(event.key) ',event.key,ord(event.key)); }
  344.  
  345. if event.key = f1 then event.sysreq := 5 else    { open window }
  346.   if event.key = f2 then event.sysreq := 6 else
  347.     if event.key = f3 then event.sysreq := 7 else      { cut window }
  348.       if event.key = f5 then event.sysreq := 9;     { move window around }
  349.  
  350.  
  351. end;
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. procedure window_manage(var event : event_record);
  359.  
  360. var
  361.   corners : quad;
  362.   columns : integer;
  363.   ch      : char;
  364.   start, stop : byte;
  365.   temp_window: window_type;   { temporary window }
  366.   temp_buf   : imagetype;
  367.   i          : integer;
  368.  
  369.  
  370. begin
  371. if event.sysreq = 5 then    { make window }
  372.  
  373. begin
  374.  wp_index := wp_index + 1;    { overall layer counter }
  375.  
  376.  { save current screen }
  377.  new(screen_stack[wp_index]);
  378.  get_screen(buffer); 
  379.  screen_stack[wp_index]^ := buffer;
  380.  
  381.  { make new window }
  382.  new(wp[wp_index]);
  383.  
  384.  corners[0]  := 40;
  385.  corners[1]  := 12;
  386.  
  387.  gotoxy(corners[0],corners[1]);
  388.  set_cursor;
  389.  
  390.  { establish NW corner of window }
  391. repeat
  392.    ch := getchar([retrn, right, down,left, up,home], false);
  393.    if (ch = left) then
  394.         corners[0] := corners[0] - 1;
  395.  
  396.    if (ch = up) then corners[1] := corners[1] - 1;
  397.    if (ch = right) then
  398.         corners[0] := corners[0] + 1;
  399.  
  400.    if (ch = down) then corners[1] := corners[1] + 1;
  401.    if (ch = home) then
  402.      begin
  403.         corners[0] := corners[0] - 1;
  404.         corners[1] := corners[1] - 1;
  405.      end;
  406.  
  407.    GotoXY(corners[0],corners[1]);
  408.  until ( ch = retrn);
  409.  
  410.  
  411.  corners[2] := corners[0];
  412.  corners[3] := corners[1];
  413.  
  414.  
  415.    { get SE corner from user  -- keep showing box }
  416.  repeat
  417.    ch := getchar([retrn, right, down,home,endd,pgup,pgdn], false);
  418.    if (ch = right) then
  419.         corners[2] := corners[2] + 1;
  420.  
  421.    if (ch = down) then corners[3] := corners[3] + 1;
  422.    if (ch = home) then
  423.      begin
  424.         corners[2] := corners[2] - 1;
  425.         corners[3] := corners[3] - 1;
  426.      end;
  427.  
  428.    if (ch = endd) then
  429.      begin
  430.         corners[2] := corners[2] - 1;
  431.         corners[3] := corners[3] - 1;
  432.      end;
  433.  
  434.    if (ch = pgup) then
  435.      begin
  436.         corners[2] := corners[2] + 1;
  437.         corners[3] := corners[3] - 1;
  438.      end;
  439.  
  440.    if (ch = pgdn) then
  441.      begin
  442.         corners[2] := corners[2] + 1;
  443.         corners[3] := corners[3] + 1;
  444.      end;
  445.  
  446.  
  447.    wp[wp_index]^.ullr := corners;
  448.    draw_window(wp[wp_index]);
  449.  until ( ch = retrn);
  450.  
  451.  
  452.  draw_window(wp[wp_index]);   { will clean inside of box }
  453.  
  454.  
  455.  
  456.  event.cursor_where[0] := corners[0]+1;
  457.  event.cursor_where[1] := corners[1]+1;
  458.      { set things up for action inside the box }
  459.  
  460.  
  461.  EVENT.Active_Window := wp[wp_index];
  462.  
  463.  reset_cursor;
  464.  
  465.  
  466.  end
  467.     { if sysreq = 5 }
  468.  else if (event.sysreq = 6) then   { zap window }
  469.   begin
  470.    if (wp_index > 1) then 
  471.  
  472.    begin            
  473.      dispose(wp[wp_index]);                { pop window stack }
  474.      if (crtmode = 7) then monobuffer := screen_stack[wp_index]^
  475.          else colorbuffer := screen_stack[wp_index]^;
  476.              { restore previous screen }
  477.      dispose(screen_stack[wp_index]);
  478.      decr(wp_index);
  479.    end
  480.   end  { if sysreq = 6 }
  481.  
  482. else if (event.sysreq = 7) then   { scroll--top window to bottom }
  483.                                   { of stack, everybody moves up one }
  484.  
  485.   begin
  486.     temp_buf           := screen_stack[wp_index]^;
  487.     temp_window        := wp[wp_index]^;
  488.                { save top of stacks }
  489.     for i := (wp_index - 1) downto 1 do
  490.      begin
  491.       screen_stack[i + 1]^ := screen_stack[i]^;
  492.       wp[i + 1]^          := wp[i]^;
  493.      end;
  494.         { pop the stacks }
  495.  
  496.     screen_stack[1]^ := temp_buf;
  497.     wp[1]^          := temp_window;
  498.  
  499.     for i := 1 to wp_index do
  500.      begin
  501.        draw_window(wp[i]);
  502.      end;
  503.  
  504.     event.cursor_where[0] := wp[i]^.ullr[0]+1;
  505.     event.cursor_where[1] := wp[i]^.ullr[1]+1;
  506.  
  507.  
  508.   end   { = 7 }
  509.  else if (event.sysreq = 8) then    { make window without getting coords }
  510. begin
  511.  wp_index := wp_index + 1;    { overall layer counter }
  512.  
  513.  { save current screen }
  514.  new(screen_stack[wp_index]);
  515.  get_screen(buffer); 
  516.  screen_stack[wp_index]^ := buffer;
  517.  
  518.  { make new window }
  519.  new(wp[wp_index]);
  520.  
  521.  wp[wp_index] := event.active_window;  { get coords that are in event_record }
  522.  
  523.  draw_window(wp[wp_index]);   { will clean inside of box }
  524.  
  525.  
  526.  
  527.  event.cursor_where[0] := corners[0]+1;
  528.  event.cursor_where[1] := corners[1]+1;
  529.      { set things up for action inside the box }
  530.  
  531.  
  532.  EVENT.Active_Window := wp[wp_index];
  533.  
  534.  
  535.  reset_cursor;
  536.  
  537.  
  538.  end
  539.  else if event.sysreq=9 then   { move window around }
  540.  
  541.  begin
  542.   { get keystroke, move frame }
  543.   repeat
  544.     with wp[wp_index]^ do begin
  545.       ch := getchar([retrn, right, down,left, up,home], false);
  546.       if (ch = left) then 
  547.            begin
  548.              decr(ullr[0]); decr(ullr[2]);
  549.            end;
  550.    
  551.       if (ch = up) then 
  552.            begin
  553.              decr(ullr[1]); decr(ullr[3]);
  554.            end;
  555.  
  556.       if (ch = right) then
  557.            begin
  558.              incr(ullr[0]); incr(ullr[2]);
  559.            end;
  560.  
  561.    
  562.       if (ch = down) then 
  563.            begin
  564.              incr(ullr[1]); incr(ullr[3]);
  565.            end;
  566.  
  567.       draw_window(wp[wp_index]);
  568.     end   { with wp[wp_index]^ }
  569.  until (ch=retrn);
  570.     { now clear screen, redraw whole system }
  571.     clrscr;
  572.     
  573.     for i := 1 to wp_index do
  574.      begin
  575.        draw_window(wp[i]);
  576.      end;
  577.  
  578.     event.cursor_where[0] := wp[i]^.ullr[0]+1;
  579.     event.cursor_where[1] := wp[i]^.ullr[1]+1;
  580.  
  581.  end;
  582.  
  583. event.sysreq := 0;
  584.  
  585. end; {manage_window...}
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592. procedure manage_system_okset(m_okset : setofchar);
  593.  
  594. begin end;
  595.  
  596.  
  597.  
  598.  
  599. procedure update_system_rec(sysrec : system_status_type);
  600.  
  601.  
  602. procedure show_status(sysrec : system_status_type);
  603.  
  604. const
  605.   slash = '/';
  606.   colon = ':';
  607.  
  608. var
  609.   h,m,s,d,y   : string[4];
  610.   datestr, timestr  : string[12];
  611.  
  612.  
  613. begin
  614.   with sysrec do
  615.   begin
  616.     str(date.day,d);
  617.     str(date.month,m);
  618.     str(date.year,y);
  619.     datestr := m + slash+ d + slash + y;
  620.     str(time.second:2,s); if s[1]=' ' then s[1] := '0';
  621.     str(time.minute:2,m); if m[1]=' ' then m[1] := '0';
  622.     str(time.hour:2,h); if h[1]=' ' then h[1] := '0';
  623.     timestr := h + colon + m + colon + s ;
  624.   end;
  625.   drawbox(1,1,10,2);
  626.   putstring(2,2,'        ');
  627.   putstring(2,3,'        ');
  628.   putstring(2,2,datestr);
  629.   putstring(2,3,timestr);
  630.  
  631. end;
  632.  
  633.  
  634.  
  635. begin   { update_system_rec }
  636. with sysrec do
  637.   begin
  638.       getdate(sysrec.date);
  639.       gettime(sysrec.time);
  640.       show_status(sysrec);
  641.  
  642.   end;
  643. end;
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650. procedure read_init_file;
  651.  
  652. var
  653.  
  654.   quad_file : file of quad;
  655.   the_quad  : quad;   { TYPE QUAD is an array[0..3] of integer }
  656.  
  657.  
  658.  
  659. begin
  660.   assign(quad_file,'config.dat');
  661.   reset(quad_file);
  662.  
  663.  
  664.   while not eof(quad_file) do 
  665.     begin
  666.       read(quad_file, the_quad);
  667.       event.sysreq := 8;
  668.       event.active_window^.ullr := the_quad;
  669.  
  670.       window_manage(event);
  671.     end;
  672.  
  673. end;   { read_init_file }
  674.  
  675.  
  676.  
  677.  
  678.  
  679. procedure update_system(var event : event_record;
  680.                         var system_status : system_status_type);
  681.  
  682. begin
  683.   update_system_rec(system_status);
  684.   gotoxy(event.cursor_where[0],event.cursor_where[1]);
  685. end;  { update_system }
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695. procedure update_sheet_window(var event : event_record);
  696.  
  697. var
  698.   temp : numstr;
  699.  
  700.  
  701. PROCEDURE PUTS(xcoord, ycoord : integer;s :numstr);
  702.  
  703. var
  704.   i :integer;
  705.  
  706. begin
  707.   for i := 1 to length(s) do putchar((xcoord + i - 1), ycoord,s[i]);
  708. end;   { PUTS }    
  709.  
  710.  
  711. PROCEDURE PUTSv(xcoord, ycoord : integer;s :numstr);
  712.  
  713. var
  714.   i :integer;
  715.  
  716. begin
  717.   for i := 1 to length(s) do putcharv((xcoord + i - 1), ycoord,s[i]);
  718. end;   { PUTS }    
  719.  
  720.  
  721.  
  722.  
  723. procedure cell_jump(ch : char);
  724.  
  725.  
  726. begin
  727.          if (ch = up) then
  728.            begin
  729.              if (sheet_record.active_cell[1]+
  730.                  sheet_record.offset[1]) > 0
  731.                 then
  732.                   begin
  733.                     decr(sheet_record.active_cell[1]);
  734.                     sheet_record.cell_pos := 1;
  735.                   end       { if (sheet.. then }
  736.            end         { if ch=up }
  737.         else
  738.          if ((ch = down) or (ch=retrn)) then
  739.            begin
  740.              if (sheet_record.active_cell[1]+
  741.                  sheet_record.offset[1]) < 8
  742.                 then
  743.                   begin
  744.                     incr(sheet_record.active_cell[1]);
  745.                     sheet_record.cell_pos := 1;
  746.                   end       { if (sheet.. then }
  747.            end         { if ch=up }
  748.         else
  749.          if (ch = left) then
  750.            begin
  751.              if (sheet_record.active_cell[0]+
  752.                  sheet_record.offset[0]) > 0
  753.                 then
  754.                   begin
  755.                     decr(sheet_record.active_cell[0]);
  756.                     sheet_record.cell_pos := 1;
  757.                   end       { if (sheet.. then }
  758.            end         { if ch=left }
  759.         else
  760.          if (ch = right) then
  761.            begin
  762.              if (sheet_record.active_cell[0]+
  763.                  sheet_record.offset[0]) < 7
  764.                 then
  765.                   begin
  766.                     incr(sheet_record.active_cell[0]);
  767.                     sheet_record.cell_pos := 1;
  768.                   end       { if (sheet.. then }
  769.            end;         { if ch=right }
  770.  
  771. end;            { procedure cell_jump}
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779. procedure num_update(ch : char);
  780.  
  781.  
  782. begin
  783.   with sheet_record do
  784.  
  785.        begin
  786.          sheet[active_cell[0],active_cell[1]][cell_pos] := ch;
  787.          { move cursor }
  788.          if cell_pos < 7 then
  789.             begin
  790.               incr(cell_pos);
  791.               incr(event.cursor_where[0]);
  792.             end;
  793.          { rewrite this cell, first blank out }
  794.          puts( (sheet_corn[0]+1+active_cell[0]*8),
  795.                     (sheet_corn[1]+1+active_cell[1]),'       ');
  796.          temp := sheet[active_cell[0],active_cell[1]];
  797.          puts( (sheet_corn[0]+1+active_cell[0]*8),
  798.                     (sheet_corn[1]+1+active_cell[1]), temp);
  799.       end;
  800. end;         { procedure num_update }
  801.  
  802.  
  803.  
  804.  
  805. procedure rp(ch : char);
  806.  
  807. { handles point mode }
  808.  
  809.  
  810. begin
  811.   with sheet_record do
  812.      begin
  813.  
  814.          if ( ((ch = down) or (ch=retrn)) and (point_mode in [o,d]) ) then
  815.            begin
  816.              if (point_mode=o) then point_mode := d;
  817.              if (sheet_record.active_cell[1]+
  818.                  sheet_record.offset[1]) < 8
  819.                 then
  820.                   begin
  821.                     incr(sheet_record.active_cell[1]);
  822.                     sheet_record.cell_pos := 1;
  823.                     putsv( (sheet_corn[0]+1+active_cell[0]*8),
  824.                     (sheet_corn[1]+1+active_cell[1]),'       ');
  825.  
  826.                     putsv( (sheet_corn[0]+1+active_cell[0]*8),
  827.                     (sheet_corn[1]+1+active_cell[1]), 
  828.                     sheet[active_cell[0],active_cell[1]]);
  829.                   end       { if (sheet.. then }
  830.            end         { if ch=down,retrn }
  831.         else
  832.          if ( (ch = right) and (point_mode in [o,r]) ) then
  833.            begin
  834.              if (point_mode=o) then point_mode := r;
  835.              if (sheet_record.active_cell[0]+
  836.                  sheet_record.offset[0]) < 7
  837.                 then
  838.                   begin
  839.                     incr(sheet_record.active_cell[0]);
  840.                     sheet_record.cell_pos := 1;
  841.                     putsv( (sheet_corn[0]+1+active_cell[0]*8),
  842.                     (sheet_corn[1]+1+active_cell[1]),'       ');
  843.  
  844.                     putsv( (sheet_corn[0]+1+active_cell[0]*8),
  845.                     (sheet_corn[1]+1+active_cell[1]),
  846.                     sheet[active_cell[0],active_cell[1]]);
  847.                   end       { if (sheet.. then }
  848.            end         { if ch=right }
  849.          else if (ch='.') then 
  850.            begin
  851.              point_mode := o;
  852.              rp_mode := false;
  853.              range.bottom[0] := sheet_corn[0]+1+active_cell[0]*8;
  854.              range.bottom[1] := sheet_corn[1]+1+active_cell[1]; 
  855.            end;
  856.  
  857.  
  858.     end; { with sheet_record do }
  859.  
  860. end;   { rp }
  861.  
  862.  
  863.  
  864. procedure rew_old_range;
  865.  
  866. var
  867.   i,r,c : integer;
  868.   ch  : char;
  869.  
  870. begin
  871.  
  872.  
  873.   with range do 
  874.    begin
  875.      for c := top[0] to bottom[0] do   { x - coordinates }
  876.        for r := top[1] to bottom[1] do   { y - coordinates }
  877.          puts(c,r,sheet[round((c-14)/8),r-3]);
  878.    end;
  879.  
  880.  
  881. end;
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891. begin  { update sheet window }
  892.  
  893.  
  894.  
  895.   with event do
  896.  
  897.    begin
  898.  
  899.     if (not rp_mode) then with sheet_record do
  900.  
  901.      begin
  902.       if (key in ['0'..'9']) then num_update(key)
  903.         else if (key in [up,down,left,right,retrn]) then
  904.           cell_jump(key)
  905.           else if (key='.') then
  906.              begin
  907.                { flip the global rp flag }
  908.  
  909.                rew_old_range;
  910.                rp_mode := true;
  911.                range.top[0] := sheet_corn[0]+1+active_cell[0]*8;
  912.                range.top[1] := sheet_corn[1]+1+active_cell[1];
  913.                { rewrite the old range as normal video }
  914.  
  915.                temp := sheet[active_cell[0],active_cell[1]];
  916.                putsv( (sheet_corn[0]+1+active_cell[0]*8),
  917.                     (sheet_corn[1]+1+active_cell[1]),
  918.                      sheet[active_cell[0],active_cell[1]]);
  919.              end  { if (key=.. }
  920.  
  921.      end  { if not rp_mode }
  922.       else
  923.        rp(key); { define range }
  924.  
  925.     
  926.  
  927.  
  928.    { now get cursor to right place }
  929.     with sheet_record do
  930.       begin
  931.          cursor_where[0] := sheet_corn[0]+active_cell[0]*8
  932.                          +cell_pos;
  933.          cursor_where[1] := sheet_corn[1]+active_cell[1]+ 1;
  934.       end;  { with sheet_record do }
  935.  
  936.    end;  { with event do }
  937.  
  938.  
  939. end;   { update sheet window }
  940.  
  941.  
  942.  
  943.  
  944.  
  945. procedure update_graph_window(event:event_record);
  946.  
  947. var
  948.   temp_duo : duo;
  949.   rl_ar    :  array[0..12] of real;
  950.   dirc     :  point_type; { r,d,o}
  951.   i,j,k,x,y    :  integer;
  952.   min,max, num_bars :real;
  953.   cd       : integer;
  954.   tempstr  : numstr;
  955.  
  956.  
  957. { get numbers from range, convert to reals, store in }
  958. { array }
  959.  
  960. begin   { update graph window }
  961.   { make it active window, clear}
  962.      if (scale > 0) then
  963.        for i := 0 to ar_sz do
  964.          for j := 0 to scale_factor do
  965.              putchar( (graph_corn[0]+j+1),(graph_corn[1]+i+1),' ');
  966.  
  967.  
  968.  
  969.  
  970.   ar_sz := 0;
  971.  
  972.  
  973.  
  974.   with range do
  975.     begin
  976.       if top[0]=bottom[0] then dirc := d else dirc := r;
  977.       getshco(top,temp_duo);
  978.       if dirc = d then ar_sz := bottom[1]-top[1]
  979.           else ar_sz := bottom[0]-top[0];
  980.     end;
  981.  
  982.  
  983.  
  984.     for i := 0 to ar_sz do   { convert strings to reals }
  985.        begin
  986.  
  987.          if dirc=d then
  988.              begin
  989.                 tempstr := sheet[temp_duo[0],temp_duo[1]+i];
  990.                 rl_ar[i] := str2real(tempstr);
  991.              end
  992.            else
  993.              begin
  994.                 tempstr := sheet[temp_duo[0]+i,temp_duo[1]];
  995.                 rl_ar[i] := str2real(tempstr);
  996.              end;
  997.        end;
  998.  
  999.  
  1000.  
  1001.  
  1002.       min := rl_ar[0]; max := min;
  1003.       for i := 1 to ar_sz do
  1004.         begin
  1005.           if rl_ar[i] < min then min := rl_ar[i];
  1006.           if rl_ar[i] > max then max := rl_ar[i];
  1007.         end;
  1008.  
  1009.       scale := max/scale_factor;
  1010.  
  1011.  
  1012.  
  1013.      if (scale > 0) then
  1014.        for i := 0 to ar_sz do
  1015.          for j := 0 to round(rl_ar[i]/scale) do
  1016.              putchar( (graph_corn[0]+j+1),(graph_corn[1]+i+1),bchk);
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024. end;    { update graph window }
  1025.  
  1026.  
  1027.  
  1028. procedure initialize;
  1029.  
  1030. var
  1031.   i,j : integer;
  1032.  
  1033.  
  1034. begin
  1035.   current_video_state(page,crtmode,width);
  1036.   init_var;
  1037.   normal; { set video attribute }
  1038.   if crtmode = 7 then buffer := monobuffer
  1039.       else buffer := colorbuffer;
  1040.   clrscr;
  1041.  
  1042.   for i := 0 to max_wide do
  1043.     for j := 0 to max_long do
  1044.       begin
  1045.         sheet[i,j] := '        ';
  1046.       end;
  1047.   system_okset := [#1..#254, up, down, left, right, escape, retrn,f1,f2,f3,f4,
  1048.         f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15];
  1049.  
  1050.   { make sheet window }
  1051.   new(wp[wp_index]);  { now wp[0] is the strings }
  1052.   wp[wp_index]^.ullr := sheet_corn;
  1053.   draw_window(wp[wp_index]);
  1054.  
  1055.   { make graph window }
  1056.   incr(wp_index);
  1057.   new(wp[wp_index]);  { now wp[1] is the graph }
  1058.   wp[wp_index]^.ullr := graph_corn;
  1059.   draw_window(wp[wp_index]);
  1060.  
  1061.   { make sheet window active }
  1062.   decr(wp_index);
  1063.   with event do
  1064.     begin
  1065.       for i := 0 to 1 do cursor_where[i] := sheet_corn[i] + 1;
  1066.       active_window := wp[wp_index];
  1067.     end;
  1068.  
  1069.   { initialize verious stuff in sheet record }
  1070.  
  1071.   sheet_record.cell_pos := 1;
  1072.  
  1073.   for i := 0 to 1 do
  1074.     begin
  1075.       sheet_record.active_cell[i] := 0;
  1076.       sheet_record.offset[i]      := 0;
  1077.     end;
  1078.  
  1079.  
  1080.  
  1081.  end;  { initialize }
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088. procedure clean_up; begin end;
  1089.  
  1090.  
  1091.  
  1092.  
  1093. begin { sheet main loop }
  1094.   initialize;
  1095.   event.key := #0;
  1096.   update_sheet_window(event);
  1097.  
  1098.  
  1099.        repeat
  1100.           get_event(event);
  1101.  
  1102.           update_sheet_window(event);
  1103.           update_graph_window(event);
  1104.           update_system(event,system_status);
  1105.         until (event.key=escape);
  1106.    clean_up; 
  1107. end.
  1108.  
  1109.